﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mamnontuoitho7.AppCode;
using System.Data;

namespace mamnontuoitho7.backend
{
    public partial class TeacherList : System.Web.UI.Page
    {

        public Class _class = new Class();
        public Teacher _teacher = new Teacher();
        protected DataTable _dttTeacher;

        //private HttpCookie cookie = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            //Check Role Admin
            if (Session["memberID"].ToString() != "" && (ConstantClass.permissionInfo).IndexOf(Session["role"].ToString() + ",") != -1)
            {
                try
                {
                    if (!IsPostBack)
                    {
                        if (Request.Form["hidTeacherVisible"] != null)
                        {
                            //Set a teacher is visible or not
                            if (Request.Form["hidTeacherVisible"].ToString() == "true")
                            {
                                _teacher.SetMemberVisible(Request.Form["hidTeacherID"].ToString(), "0");
                            }
                            else if (Request.Form["hidTeacherVisible"].ToString() == "false")
                            {
                                _teacher.SetMemberVisible(Request.Form["hidTeacherID"].ToString(), "1");
                            }
                        }

                        if (Request.Cookies[ConstantClass.cooTeacherList_ddlStatus] == null)
                        {
                            HttpCookie cookie = new HttpCookie(ConstantClass.cooTeacherList_ddlStatus, "1");
                            Response.Cookies.Add(cookie);
                            cookie.Expires = DateTime.Now.AddDays(1);
                        }

                        _dttTeacher = _teacher.GetTeacherList(Request.Cookies[ConstantClass.cooTeacherList_ddlStatus].Value);
                        ddlShowTeacher.SelectedValue = Request.Cookies[ConstantClass.cooTeacherList_ddlStatus].Value;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Response.Redirect(ConstantClass._errorAdminPage);
                }
            }
            else
            {
                Response.Redirect(ConstantClass._errorLoginPage);
            }
        }


        protected void ddlShowTeacher_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                _dttTeacher = _teacher.GetTeacherList(ddlShowTeacher.SelectedValue);
                if (Request.Cookies[ConstantClass.cooTeacherList_ddlStatus] == null)
                {
                    HttpCookie cookie = new HttpCookie(ConstantClass.cooTeacherList_ddlStatus, ddlShowTeacher.SelectedValue);
                    Response.Cookies.Add(cookie);
                }
                else
                {
                    Response.Cookies[ConstantClass.cooTeacherList_ddlStatus].Value = ddlShowTeacher.SelectedValue;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Response.Redirect(ConstantClass._errorAdminPage);
            }
        }
    }
}